﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DreamBox.Admin.User
{
    public partial class CompetenceUpdate : BLL.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //
                if (Request.QueryString["ComID"] != null)
                {
                    DAL.Admin.GetCompetence com = new DAL.Admin.GetCompetence();
                    DropParentID.DataSource = com.GetList();
                    DropParentID.DataTextField = "CompetenceName";
                    DropParentID.DataValueField = "ComID";
                    DropParentID.DataBind();

                    DropParentID.Items.Insert(0, new ListItem("无上级权限", "0"));

                    DAL.PSelect ps = new DAL.PSelect();
                    DataTable dt = ps.Select("dbox_UserCompetence","*","ComID="+Request.QueryString["ComID"]);
                    ComName.Text = dt.Rows[0]["CompetenceName"].ToString();
                    ComUrl.Text = dt.Rows[0]["Url"].ToString();
                    NodeCount.Text = dt.Rows[0]["NodeCount"].ToString();

                    foreach (ListItem item in DropParentID.Items)
                    {
                        if (item.Value == dt.Rows[0]["ParentID"].ToString())
                        {
                            item.Selected = true;
                        }
                    }
                }
            }
        }
        protected void btnPost_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ComID"] != null)
            {
                Model.Admin.Competence m = new Model.Admin.Competence();
                m.ComID = int.Parse(Request.QueryString["ComID"]);
                m.CompetenceName = ComName.Text;
                m.Url = ComUrl.Text;
                m.NodeCount = int.Parse(NodeCount.Text);
                m.IsType = 1;
                m.ParentID = int.Parse(DropParentID.SelectedValue);
                DAL.Admin.Competence com = new DAL.Admin.Competence();
                if (com.Update(m))
                {
                    BLL.Admin.Tips.DetailedTips(this, "编辑成功", "/User/CompetenceList.aspx", "1");
                }
            }
        }
    }
}